﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HomeAutomation.actions;

namespace HomeAutomation
{
    class DeviceFlowEvent : FlowEvent
    {
        private DeviceAction deviceAction { get; set; }

        public DeviceFlowEvent(DeviceAction deviceAction)
        {
            this.deviceAction = deviceAction;
        }

  

        public override bool Equals(System.Object obj)
        {

            if (obj != null && obj is DeviceFlowEvent)
            {
                DeviceFlowEvent deviceFlowEvent = (DeviceFlowEvent)obj;

                if (deviceAction == null && deviceFlowEvent.deviceAction == null)
                {
                    return true;
                }

                if (deviceFlowEvent.deviceAction != null)
                {
                    return deviceFlowEvent.deviceAction.Equals(deviceAction);
                    //if (deviceAction.device == deviceFlowEvent.deviceAction.device &&
                    //    deviceAction.command == deviceFlowEvent.deviceAction.command)
                    //{
                    //    return true;
                    //}
                }
            }

            return false;

            //// If parameter is null return false.
            //if (obj == null)
            //{
            //    return false;
            //}

            //// If parameter cannot be cast to Point return false.
            //TwoDPoint p = obj as TwoDPoint;
            //if ((System.Object)p == null)
            //{
            //    return false;
            //}

            //// Return true if the fields match:
            //return (x == p.x) && (y == p.y);
        }

        public override int GetHashCode()
        {
            int hash = 31;
            hash = hash * 17 + (deviceAction != null ? deviceAction.GetHashCode() : 0);
            return hash;
        }
    }
}
